<template>
  <div class="chat-user" @click="goChat">
    <van-row type="flex" justify="space-between" align="center">
      <van-col span="4">
        <van-image
          round
          width="50px"
          height="50px"
          :src="user.decorate_avatar"
        />
      </van-col>
      <van-col class="text-info" span="14">
        <div class="name">
          {{ user.teacher ? user.teacher : user.username }}
        </div>
        <div class="msg">{{ user.newest_message }}</div>
      </van-col>
      <van-col span="4">
        <div class="time">
          <span>{{ user.newest_create_time | dateFormat }}</span>
        </div>
        <div class="badge" v-show="user.unread_message > 0">
          <van-icon :badge="user.unread_message" />
        </div>
      </van-col>
    </van-row>
  </div>
</template>

<script>
export default {
  props: ["user"],
  methods: {
    goChat() {
      this.$router.push(`chat/${this.user.id}`);
    },
  },
};
</script>

<style lang="less" scoped>
.chat-user {
  font-size: 14px;
  padding: 10px;
  box-sizing: border-box;
  border-bottom: 1px solid #f0f0f0;
}
.text-info {
  margin-left: 5px;
  margin-right: auto;
}
.name {
  color: #191919;
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1; // 具体第几行自定定义
}
.msg {
  margin-top: 5px;
  font-size: 12px;
  color: #999999;
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1; // 具体第几行自定定义
}
.time {
  font-size: 12px;
  color: #999999;
  text-align: right;
}
.badge {
  float: right;
  margin-right: 10px;
}
</style>